package com.test.interceptor;

import com.jfinal.aop.Interceptor;
import com.jfinal.aop.Invocation;
import com.test.model.Users;

import javax.servlet.http.HttpSession;

public class DemoInterceptor implements Interceptor {
    public void intercept(Invocation inv) {
        HttpSession session=inv.getController().getSession();
        Users users = (Users) session.getAttribute("user");
        if (null==users){
            //没登陆
            inv.getController().redirect("/login");
        }else {
            //登录了
            inv.invoke();
        }
//        System.out.println("session"+users);
//        inv.invoke();
//        System.out.println("After method invoking");
    }
}